package com.question_barrier.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回的数据格式
 */

@ApiModel("结果对象")
public class ResultModel<T> implements Serializable {
    @ApiModelProperty("响应码")
    private int code;
    @ApiModelProperty("描述")
    private String msg;
    @ApiModelProperty("数据")
    private T data ;

    public ResultModel(){}

    public ResultModel(int errorCode, String msg, T data) {
        this.code = errorCode;
        this.msg = msg;
        this.data = data;
    }
    public  void chooseMsg(){
        if (this != null) {
            int code = this.getCode();
            switch (code) {
                case 10000:
                    this.setMsg("网络繁忙,请稍后重试");
                    break;
                case 10001:
                    this.setMsg("无此用户");
                    break;
                case 10002:
                    this.setMsg("添加成功");
                    break;
                case 10003:
                    this.setMsg("删除成功");
                    break;
                case 10004:
                    this.setMsg("更新成功");
                    break;
                case -1:
                    this.setMsg("请求失败");
                    break;
                case 10005:
                    this.setMsg("此用户已存在");
                    break;
                case 10006:
                    this.setMsg("添加失败");
                    break;
                case 10007:
                    this.setMsg("删除失败");
                    break;
                case 10008:
                    this.setMsg("更新失败");
                    break;
                case 10009:
                    this.setMsg("获取成功");
                    break;
                case 10010:
                    this.setMsg("获取失败");
                    break;
                case 10011:
                    this.setMsg("已经是最高关卡");
                    break;
                default:
                    this.setMsg("请求成功");
                    break;
            }
        }
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
